#ifndef FRAMEWORK_LOG_H
#define FRAMEWORK_LOG_H

#include <stdio.h>
#include <string>
#include "../policies/singleton.h"

namespace project_w_framework {

	enum LogLevel
	{
		LOG_LVL_MINIMAL = 0,                                    // unconditional and errors
		LOG_LVL_BASIC   = 1,
		LOG_LVL_DETAIL  = 2,
		LOG_LVL_DEBUG   = 3
	};

	enum Color
	{
		BLACK,
		RED,
		GREEN,
		BROWN,
		BLUE,
		MAGENTA,
		CYAN,
		GREY,
		YELLOW,
		LRED,
		LGREEN,
		LBLUE,
		LMAGENTA,
		LCYAN,
		WHITE
	};

	const int Color_count = int(WHITE)+1;

	class Log : public project_w_framework::Singleton<Log>
	{
		public:
			Log();
			~Log()
			{
				if( logfile != NULL )
				{
					fclose(logfile);
				}

				logfile = NULL;
			}
			void Initialize();
			void InitColors(const std::string& init_str);
			void outTitle( const char * str);
			void outString();
			void outString( const char * str, ... );
			void outError( const char * err, ... );
			void SetColor(bool stdout_stream, Color color);
			void ResetColor(bool stdout_stream);
			void outTime();
			static void outTimestamp(FILE* file);
			static std::string GetTimestampStr();
			bool IsIncludeTime() const { return m_includeTime; }

			static void WaitBeforeContinueIfNeed();

		private:
			FILE* openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode);

			FILE* logfile;
			bool m_colored;
			bool m_includeTime;
			Color m_colors[4];

			// cache values for after initilization use (like gm log per account case)
			std::string m_logsDir;
			std::string m_logsTimestamp;
	};
}

#define sLog project_w_framework::Singleton<project_w_framework::Log>::Instance()

#endif
